package com.itheima.exerciseTest.method40_49.method48;

import java.io.*;

import java.util.Scanner;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class CopyFileDemo {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(2,
                5,
                1, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

//        File file1 = new File("backBurner\\a\\源氏头像.jpg");
//        File file2 = new File("backBurner\\a\\源氏头像.jpg");
//        ThreadCopyFile tcf1 = new ThreadCopyFile(file1);
//        ThreadCopyFile tcf2 = new ThreadCopyFile(file2);
//        pool.submit(tcf1);
//        pool.submit(tcf2);
//        pool.shutdown();
        while(true){
            boolean boo = true;
            System.out.println("请输入要复制的文件地址：");
            String str = sc.nextLine().trim();
            File file = new File(str);
            if (!file.isFile()) {
                System.out.println("您输入的文件地址值不格式不正确");
                boo = false;
            }else if(!file.exists()){
                System.out.println("您输入的文件地址值不存在");
                boo = false;
            }
            if(boo == false){
                System.out.println("退出 Y/y，继续任意键");
                String strr = sc.nextLine().trim();
                if("Y".equals(strr) || "y".equals(strr)){
                    break;
                }
            }
            ThreadCopyFile tcf = new ThreadCopyFile(file);
            pool.submit(tcf);
        }
        pool.shutdown();
    }
}
